package cst.neu.yuejian_31.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.util.List;

import cst.neu.yuejian_31.Common.Constant;
import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.bean.UserInfoBean;
import cst.neu.yuejian_31.iface.UserInfoListener;
import cst.neu.yuejian_31.model.UserInfoModel;

public class UserActivity extends BaseActivity implements View.OnClickListener,UserInfoListener {

    private String userId;
    private TextView userName,userTel,self;
    private ImageView userPhoto,btn_return;
    private ImageButton returnButton,postButton,attentionButton,orderButton;
    private Button yuejianButton,scanfButton;
    private List<UserInfoBean> list;
    private UserInfoBean user;
    private SharedPreferences sp;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        initViews();
        initEvents();
        initData();
    }

    private void initEvents() {
        self.setOnClickListener(this);
        yuejianButton.setOnClickListener(this);
        postButton.setOnClickListener(this);
        attentionButton.setOnClickListener(this);
        orderButton.setOnClickListener(this);
        btn_return.setOnClickListener(this);

    }

    private void initData() {
       String userid=getUserId();
        UserInfoModel model=new UserInfoModel();
        model.getUserInfo(userid,this);
    }

    @Override
    public void onResponse(UserInfoBean userInfoBean) {

        userName.setText(userInfoBean.getUsername());
        userTel.setText(userInfoBean.getUserphone());
        Picasso.with(UserActivity.this).load(Constant.USER_URL+userInfoBean.getUser_pic()).into(userPhoto);

    }

    @Override
    public void onFail(String msg) {

    }

    private void initViews() {
        userName= (TextView) findViewById(R.id.textView_username);
        userTel= (TextView) findViewById(R.id.textView_userphone);
        userPhoto= (ImageView) findViewById(R.id.imageView_user_detail);
        yuejianButton= (Button) findViewById(R.id.button_yuejian);
        self= (TextView) findViewById(R.id.textView_self);
        postButton=(ImageButton) findViewById(R.id.imageButton_post);
        attentionButton= (ImageButton) findViewById(R.id.imageButton_attention);
        orderButton= (ImageButton) findViewById(R.id.imageButton_order);
        btn_return= (ImageView) findViewById(R.id.imageButton_return_set);




    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button_yuejian:
                Intent intent1=new Intent(UserActivity.this,YuejianActivity.class);
                startActivity(intent1);
                break;
            case R.id.textView_self:
                Intent intent2=new Intent(UserActivity.this,SettingActivity.class);
                startActivity(intent2);
                break;
            case  R.id.imageButton_post:
                Intent intent3=new Intent(UserActivity.this,UserPostActivity.class);
                startActivity(intent3);
                break;
            case R.id.imageButton_attention:
                Intent intent4=new Intent(UserActivity.this,AttentionActivity.class);
                startActivity(intent4);
                break;
            case R.id.imageButton_order:
                Intent intent5=new Intent(UserActivity.this,OrderActivity.class);
                startActivity(intent5);
                break;
            case R.id.imageButton_return_set:
                finish();
                break;

        }

    }
}
